//
//  AppDelegate.m
//  联付商圈
//
//  Created by 于洋 on 2017/7/14.
//  Copyright © 2017年 lianfu. All rights reserved.
//

#import "AppDelegate.h"
#import "YYModel.h"

@interface AppDelegate ()

@property (nonatomic, strong)SQUserModel *userModel;

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    self.window.backgroundColor = [UIColor whiteColor];
    
    LBTabBarController *tabBarVc = [[LBTabBarController alloc] init];
    
    self.window.rootViewController = tabBarVc;
    
    [self.window makeKeyAndVisible];

//    向微信注册wxd930ea5d5a258f4f
//    [WXApi registerApp:@"wxb4ba3c02aa476ea1"];
    
    //[AMapServices sharedServices].apiKey = @"d7ecae79dc73faaeb7a6dbc196aa6e82";
    return YES;
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
{
    // 跳转到URL scheme中配置的地址
    //NSLog(@"跳转到URL scheme中配置的地址-->%@",url);
    if ([url.host isEqualToString:@"safepay"]) {
        [self paymentResult:url];
        return YES;
    }else {        
//        return [WXApi handleOpenURL:url delegate:(id<WXApiDelegate>)self];
        return NO;
    }
}
//支付成功时调用，回到第三方应用中
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    //    NSLog(@"****************url.host -- %@",url.host);
//    if ([url.scheme isEqualToString:@"wxb4ba3c02aa476ea1"])
//    {
//        return  [WXApi handleOpenURL:url delegate:(id<WXApiDelegate>)self];
//    }
    if ([url.host isEqualToString:@"safepay"]) {
        [self paymentResult:url];
    }
    return YES;
    
    
}

//- (void)onResp:(BaseResp *)resp
//{
//    //    支付结果回调
//    if([resp isKindOfClass:[PayResp class]]){
//        
//        switch (resp.errCode) {
//            case WXSuccess:{
//                
//                //支付返回结果，实际支付结果需要去自己的服务器端查询
//                NSNotification *notification = [NSNotification notificationWithName:@"ORDER_PAY_NOTIFICATION" object:@"success"];
//                [[NSNotificationCenter defaultCenter] postNotification:notification];
//                
//                break;
//            }
//            default:{
//                NSNotification *notification = [NSNotification notificationWithName:@"ORDER_PAY_NOTIFICATION"object:@"fail"];
//                [[NSNotificationCenter defaultCenter] postNotification:notification];
//                break;
//            }
//        }
//    }
//}

- (void)paymentResult:(NSURL *)url
{
    //跳转支付宝钱包进行支付，处理支付结果
    [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic) {
        NSLog(@"result = %@",resultDic);
    }];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}





- (void)applicationDidBecomeActive:(UIApplication *)application {
    //[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadNotification" object:nil];
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

